package com.stu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stu.entity.Student;
import com.stu.mapper.CollegeMapper;
import com.stu.mapper.MajorMapper;
import com.stu.mapper.StudentMapper;
import com.stu.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private MajorMapper majorMapper;

    @Autowired
    private CollegeMapper collegeMapper;


    @Override
    public void insertDemo() {

    }

    @Override
    public List<Student> list() {
        List<Student> stuList = studentMapper.getStuList();
        return stuList;
    }

    @Override
    public Page page(int page, int limit, String name) {
        Page pageInfo = new Page(page, limit);

        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        if (null != name) {
            queryWrapper.like(Student::getName, name);
        }
        return studentMapper.selectPage(pageInfo, queryWrapper);
    }

    @Override
    public List<Student> getPage(Integer page, Integer limit) {
        page = (page - 1) * limit;
        return studentMapper.getPage(page, limit);
    }


    //返回学生表，专业表，学院表总条数----统计表中行
    @Override
    public Integer[] getAllRow() {
        Integer[] integers1 = new Integer[3];
        integers1[0]=studentMapper.selectCount(null);
        integers1[2]=collegeMapper.selectCount(null);
       integers1[1]=majorMapper.selectCount(null);
        return integers1;
    }


}
